package com.hangwei.aicabinet.util;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hangwei.aicabinet.R;


public class LoadingDialog {

    public static Dialog showDialog(Context context, String tipMsg) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.dialog_loading, null);
        TextView tvMsg = v.findViewById(R.id.tvMsg);
        if (!TextUtils.isEmpty(tipMsg)) {
            tvMsg.setVisibility(View.VISIBLE);
            tvMsg.setText(tipMsg + "...");
        } else {
            tvMsg.setVisibility(View.GONE);
        }
        Dialog loadingDialog = new Dialog(context, R.style.generic_dialog);
        loadingDialog.setCancelable(false);// 不可以用“返回键”取消
        loadingDialog.setCanceledOnTouchOutside(false);
        loadingDialog.setContentView(v, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
        return loadingDialog;
    }

}